package com.ruoyi.petSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.petSys.entity.vo.AddFriendVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.petSys.domain.AddFriend;
import com.ruoyi.petSys.service.IAddFriendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 添加好友Controller
 * 
 * @author ruoyi
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/petSys/addFriend")
public class AddFriendController extends BaseController
{
    @Autowired
    private IAddFriendService addFriendService;

    /**
     * 查询添加好友列表
     */
//    @PreAuthorize("@ss.hasPermi('petSys:addFriend:list')")
    @GetMapping("/list")
    public TableDataInfo list(AddFriend addFriend)
    {
        startPage();
        List<AddFriendVo> list = addFriendService.selectAddFriendList(addFriend);
        return getDataTable(list);
    }

    /**
     * 导出添加好友列表
     */
//    @PreAuthorize("@ss.hasPermi('petSys:addFriend:export')")
    @Log(title = "添加好友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AddFriend addFriend)
    {
        List<AddFriendVo> list = addFriendService.selectAddFriendList(addFriend);
        ExcelUtil<AddFriendVo> util = new ExcelUtil<AddFriendVo>(AddFriendVo.class);
        util.exportExcel(response, list, "添加好友数据");
    }

    /**
     * 获取添加好友详细信息
     */
//    @PreAuthorize("@ss.hasPermi('petSys:addFriend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(addFriendService.selectAddFriendById(id));
    }

    /**
     * 新增添加好友
     */
//    @PreAuthorize("@ss.hasPermi('petSys:addFriend:add')")
    @Log(title = "添加好友", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddFriend addFriend)
    {
        return toAjax(addFriendService.insertAddFriend(addFriend));
    }

    /**
     * 修改添加好友
     */
//    @PreAuthorize("@ss.hasPermi('petSys:addFriend:edit')")
    @Log(title = "添加好友", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddFriend addFriend)
    {
        return toAjax(addFriendService.updateAddFriend(addFriend));
    }

    /**
     * 删除添加好友
     */
    @PreAuthorize("@ss.hasPermi('petSys:addFriend:remove')")
    @Log(title = "添加好友", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(addFriendService.deleteAddFriendByIds(ids));
    }
}
